-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix derive(PartialOrd) and optimise final field operation #49881
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
I might also look into reducing the number of comparison operations further, following this suggestion. But I'm not sure if I'll get to it right away. |
These now spit out errors for `<=` and `>=` as well.
r? @alexcrichton or @Manishearth |
let not_cmp = cx.expr_unary(span, | ||
ast::UnOp::Not, | ||
cx.expr_binary(span, op, other_f.clone(), self_f)); | ||
let deleg_cmp = if !equal { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the comment above with the new generated code for the <= case
} | ||
} | ||
|
||
/// Special version of `cs_fold` that uses the result of a function call on the first field | ||
/// as the base case when is at least 1 field, and the usual base case when there are zero fields. | ||
pub fn cs_fold1<F, B>(use_foldl: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs clearer documentation
let eq = cx.expr_binary(span, BinOpKind::Ne, self_f, other_f.clone()); | ||
cx.expr_binary(span, BinOpKind::Or, subexpr, eq) | ||
}, | ||
|cx, args| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this and the previous closure can be factored out into a function
Overall looks good, minor nits |
(1, Some(o_f)) => o_f, | ||
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`"), | ||
}; | ||
let eq = |cx: &mut ExtCtxt, span: Span, self_f: P<Expr>, other_fs: &[P<Expr>]| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant splitting this out into a function such that it can be shared between the Eq and Neq code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh... that's another good idea! 😅
r? @Manishearth |
@bors r+ |
📌 Commit 105c518 has been approved by |
Fix derive(PartialOrd) and optimise final field operation ```rust // Before (`lt` on 2-field struct) self.f1 < other.f1 || (!(other.f1 < self.f1) && (self.f2 < other.f2 || (!(other.f2 < self.f2) && (false) )) ) // After self.f1 < other.f1 || (!(other.f1 < self.f1) && self.f2 < other.f2 ) // Before (`le` on 2-field struct) self.f1 < other.f1 || (!(other.f1 < self.f1) && (self.f2 < other.f2 || (!(other.f2 < self.f2) && (true) )) ) // After self.f1 < other.f1 || (self.f1 == other.f1 && self.f2 <= other.f2 ) ``` (The big diff is mainly because of a past faulty rustfmt application that I corrected 😒) Fixes #49650 and fixes #49505.
☀️ Test successful - status-appveyor, status-travis |
(The big diff is mainly because of a past faulty rustfmt application that I corrected 😒)
Fixes #49650 and fixes #49505.